﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using iTextSharp.text.html;

using iTextSharp.text.html.simpleparser;
using iTextSharp.text;
using iTextSharp.text.pdf;
using University.Workshop.DataAccess;
using University.Workshop.Model;
using System.IO;

namespace University.Workshop.WinApp
{
    public class Reportes
    {

        private void Reports_Load()
        {
             Reporte reporte = new Reporte();
            reporte.ClienteExistentes();
            Document document = new Document(PageSize.LETTER, 50, 40, 40, 40);

            PdfWriter.GetInstance(document, new FileStream(@"D:ReporteClientesExistentes.pdf", FileMode.OpenOrCreate));
            document.Open();

            Chunk chunk1 = new Chunk("Hotel - Client Report", FontFactory.GetFont(FontFactory.TIMES_ROMAN, 18, iTextSharp.text.Font.UNDERLINE));
            Chunk chunk2 = new Chunk("Cochabamba, " + DateTime.Now.ToString(), FontFactory.GetFont(FontFactory.TIMES_ROMAN, 14, iTextSharp.text.Font.NORMAL));

            Paragraph paragraph = new Paragraph();
            Paragraph paragraph1 = new Paragraph();

            paragraph.Add(chunk1);
            paragraph1.Add(chunk2);
            paragraph.Alignment = Element.ALIGN_CENTER;
            paragraph1.Alignment = Element.ALIGN_LEFT;

            document.Add(paragraph);
            document.Add(new Paragraph("\n\r"));
            document.Add(paragraph1);
            document.Add(new Paragraph("\n\r"));
            Cliente cli = new Cliente();

            DataTable resultado = cli.CargarClientes();

            PdfPTable table = new PdfPTable(6);
            PdfPCell cell = new PdfPCell();

            cell.Colspan = 3;
            cell.Rowspan = 1;
            cell.Padding = 1;
            //cell.PaddingLeft = 1;
            //cell.PaddingRight = 1;

            cell.HorizontalAlignment = 1; //0=Left, 1=Centre, 2=Right
            iTextSharp.text.Font titulos = FontFactory.GetFont(FontFactory.HELVETICA, 11, iTextSharp.text.Font.BOLD);

            //table.AddCell(cell);
            table.AddCell(new Phrase("FULLNAME", titulos));
            table.AddCell(new Phrase("ID", titulos));
            table.AddCell(new Phrase("PHONE", titulos));
            table.AddCell(new Phrase("E-MAIL", titulos));
            table.AddCell(new Phrase("ORG.", titulos));
            table.AddCell(new Phrase("COUNTRY", titulos));

            for (int a = 0; a < resultado.Rows.Count; a++)
            {
                table.AddCell(resultado.Rows[a].ItemArray[0].ToString());
                table.AddCell(resultado.Rows[a].ItemArray[1].ToString());
                table.AddCell(resultado.Rows[a].ItemArray[2].ToString());
                table.AddCell(resultado.Rows[a].ItemArray[3].ToString());
                table.AddCell(resultado.Rows[a].ItemArray[4].ToString());
                table.AddCell(resultado.Rows[a].ItemArray[5].ToString());
            }
            document.Add(table);
            document.Close();
            System.Diagnostics.Process.Start("D:ReporteClientesExistentes.pdf");
            }
            
        }
    }

